package com.swz.dcrm.adpter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.swz.dcrm.R;
import com.swz.dcrm.base.ViewHolder;
import com.swz.dcrm.model.VisitRecord;
import com.swz.dcrm.util.DateUtils;
import com.timehop.stickyheadersrecyclerview.StickyRecyclerHeadersAdapter;



import java.util.Date;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class VisitRecordAdapter extends CustomAdapter<VisitRecord> implements StickyRecyclerHeadersAdapter<VisitRecordAdapter.HeaderViewHolder> {
    public VisitRecordAdapter(Context context, List<VisitRecord> datas) {
        super(context,R.layout.item_visit_type1, datas);
    }

    @Override
    public long getHeaderId(int position) {
        if(getDatas()!=null&&getDatas().size()>0){
            Date date=DateUtils.dateParse(mDatas.get(position).getCreateTime(),"yyyy-MM-dd");
            return date.getTime();
        }
        return 0;
    }

    @Override
    public HeaderViewHolder onCreateHeaderViewHolder(ViewGroup parent) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_time,parent,false);
        return new HeaderViewHolder(view);
    }

    @Override
    public void onBindHeaderViewHolder(HeaderViewHolder headerViewHolder, int i) {
        headerViewHolder.date.setText(DateUtils.dateFormat(mDatas.get(i).getCreateTime(),"yyyy/MM/dd"));
    }

    @Override
    protected void convert(ViewHolder holder, VisitRecord visitRecord, int position) {
        holder.setText(R.id.tv_type, mContext.getString(R.string.clue_detail_visit_record));
        holder.setText(R.id.tv_way, visitRecord.getFollowTypeDesc());
        holder.setText(R.id.tv_time, DateUtils.dateFormat(visitRecord.getCreateTime(), "HH:mm"));
        holder.setText(R.id.tv_dec1,mContext.getString(R.string.item_result, visitRecord.getContactResultDesc()));
        holder.setText(R.id.tv_dec2, mContext.getString(R.string.item_next_plan,visitRecord.getNextFollowPurposeDesc()));

    }

    public static class HeaderViewHolder extends RecyclerView.ViewHolder{

        @BindView(R.id.tv_date)
        TextView date;

        public HeaderViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }


}
